//
//  SZWelcomeViewController.m
//  Weibo
//
//  Created by Zahi on 2017/7/30.
//  Copyright © 2017年 Zahi. All rights reserved.
//

#import "SZWelcomeViewController.h"
#import "SZAccountViewModel.h"
#import "SZUserAccount.h"


@interface SZWelcomeViewController ()

/**背景图片**/
@property (nonatomic, strong) UIImageView *bgImgView;
/**头像图片**/
@property (nonatomic, strong) UIImageView *iconImgView;
/**提示信息**/
@property (nonatomic, strong) UILabel *msgLabel;


@end

@implementation SZWelcomeViewController

#pragma mark - 加载视图
- (void)loadView
{
    self.view = self.bgImgView;
}

#pragma mark - 视图加载完成
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupUI];
}

#pragma mark - 视图已经出现
- (void)viewDidAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    // 设置动画效果
    [self setupAnimation];
}


#pragma mark - 设置UI
- (void)setupUI {
    [self.view addSubview:self.iconImgView];
    [self.view addSubview:self.msgLabel];
    
    [self.iconImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(200);
        make.centerX.equalTo(self.view);
        make.size.mas_equalTo(CGSizeMake(90, 90));
    }];
    
    [self.msgLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.iconImgView.mas_bottom).offset(10);
        make.centerX.equalTo(self.iconImgView);
    }];
}

#pragma mark - 设置动画
- (void)setupAnimation {
    
    [self.iconImgView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.offset(100);
    }];
    
    [UIView animateWithDuration:1.0 delay:0 usingSpringWithDamping:0.7 initialSpringVelocity:10 options:0 animations:^{
        
        [self.view layoutIfNeeded];
        
    } completion:^(BOOL finished) {
        
        [UIView animateWithDuration:1 animations:^{
            
            self.msgLabel.alpha = 1;
        } completion:^(BOOL finished) {
        
            [kNotificationCenter postNotificationName:SwitchRootVCNotificationName object:nil];
        }];
        
    }];
    
}


#pragma mark -  ---懒加载---
#pragma mark  背景图片
- (UIImageView *)bgImgView
{
    if (_bgImgView == nil) {
        _bgImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ad_background"]];
    }
    return _bgImgView;
}
#pragma mark  头像
- (UIImageView *)iconImgView
{
    if (_iconImgView == nil) {
        _iconImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"avatar_default_big"]];
        
        NSString *imgUrl = SZAccountViewModel.shared.account.avatar_large;
        
        [_iconImgView sd_setImageWithURL:[NSURL URLWithString:imgUrl] placeholderImage:[UIImage imageNamed:@"avatar_default_big"]];
        
        _iconImgView.layer.cornerRadius = 45;
        _iconImgView.layer.masksToBounds = YES;
    }
    return _iconImgView;
}

#pragma mark  提示文字
- (UILabel *)msgLabel
{
    if (_msgLabel == nil) {
        _msgLabel = [UILabel new];
        
        NSString *name = SZAccountViewModel.shared.account.name;
        
        _msgLabel.text = [NSString stringWithFormat:@"欢迎回来,%@",name];
        
        _msgLabel.textColor = [UIColor darkGrayColor];
        _msgLabel.font = [UIFont systemFontOfSize:13];
        _msgLabel.textAlignment = NSTextAlignmentCenter;
        _msgLabel.alpha = 0;
    }
    return _msgLabel;
}



@end
